|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.ObjectField
public class Field
Represent a rectangular grid of field positions. Each position is able to store a single animal.
| Constructor Summary | |
|---|---|
Field(int depth,
int width)
Represent a field of the given dimensions. |
|
| Method Summary | |
|---|---|
List<Location> |
adjacentLocations(Location location)
Return a shuffled list of locations adjacent to the given one. |
void |
clear()
Empty the field. |
void |
clear(Location location)
Clear the given location. |
Location |
freeAdjacentLocation(Location location)
Try to find a free location that is adjacent to the given location. |
int |
getDepth()
Return the depth of the field. |
List<Location> |
getFreeAdjacentLocations(Location location)
Get a shuffled list of the free adjacent locations. |
Object |
getObjectAt(int row,
int col)
Return the animal at the given location, if any. |
Object |
getObjectAt(Location location)
Return the animal at the given location, if any. |
int |
getWidth()
Return the width of the field. |
void |
place(Object animal,
int row,
int col)
Place an animal at the given location. |
void |
place(Object animal,
Location location)
Place an animal at the given location. |
Location |
randomAdjacentLocation(Location location)
Generate a random location that is adjacent to the given location, or is the same location. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Field(int depth,
int width)
depth - The depth of the field.width - The width of the field.| Method Detail |
|---|
public List<Location> adjacentLocations(Location location)
location - The location from which to generate adjacencies.
public void clear()
public void clear(Location location)
location - The location to clear.public Location freeAdjacentLocation(Location location)
location - The location from which to generate an adjacency.
public int getDepth()
public List<Location> getFreeAdjacentLocations(Location location)
location - Get locations adjacent to this.
public Object getObjectAt(int row,
int col)
row - The desired row.col - The desired column.
public Object getObjectAt(Location location)
location - Where in the field.
public int getWidth()
public void place(Object animal,
int row,
int col)
animal - The animal to be placed.row - Row coordinate of the location.col - Column coordinate of the location.
public void place(Object animal,
Location location)
animal - The animal to be placed.location - Where to place the animal.public Location randomAdjacentLocation(Location location)
location - The location from which to generate an adjacency.
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||